﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using U16 = System.UInt16;
using U32 = System.UInt32;
using I32 = System.Int32;
using F64 = System.Double;
using I16 = System.Int16;
namespace CSPCI1000
{
	public static class PCIInvoke
	{
		public enum ERRCode
		{
			DataPara = 2147483647 - 3,
			AxisPara,
			NoCard,
			NoError
		}
		public const string ExternDLLName = "Pci1000.dll";
		public const CallingConvention PCICallingConvention = CallingConvention.StdCall;

		#region 控制卡初始化
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern U32 w1000_initial();

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_close();

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_get_operate_mode(U16 AxisNo, ref U16 op_mode);
		#endregion

		#region 脉冲设置函数
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_set_pls_outmode(U16 AxisNo, U16 pls_outmode);
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_set_filter(U16 AxisNo, U16 en_filter);
		#endregion

		#region 点位运动函数
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_t_move(U16 AxisNo, I32 Dis, I32 StrVel, I32 MaxVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_ta_move(U16 AxisNo, I32 Pos, I32 StrVel, I32 MaxVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_s_move(U16 AxisNo, I32 Dis, I32 StrVel, I32 MaxVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_sa_move(U16 AxisNo, I32 Pos, I32 StrVel, I32 MaxVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_fix_speed_range(U16 AxisNo, F64 MaxVel);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_unfix_speed_range(U16 AxisNo);
		#endregion

		#region 特殊运动函数
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_set_sd(U16 AxisNo, U16 SDMode);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_home_move(U16 AxisNo, I32 StrVel, I32 MaxVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_sd_stop(U16 AxisNo);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_emg_stop(U16 AxisNo);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_set_el(U16 AxisNo, U16 el_mode);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_set_org(U16 AxisNo, U16 org_mode);
		#endregion

		#region 状态检测函数
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern U32 w1000_get_io_status(U16 AxisNo);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern U32 w1000_motion_done(U16 AxisNo);
		#endregion

		#region 计数器操作函数
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_set_cmd_pos(U16 AxisNo, I32 Pos);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern I32 w1000_get_cmd_pos(U16 AxisNo);
		#endregion

		#region 开关量IO函数
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern U32 w1000_read_di(U16 BitNo);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern U32 w1000_write_do(U16 BitNo, U16 BitData);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern U32 w1000_read_do(U16 BitNo);
		#endregion

		#region 连续运动函数
		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_tv_move(U16 AxisNo, I32 StrVel, I32 MaxVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_sv_move(U16 AxisNo, I32 StrVel, I32 MaxVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_v_change(U16 AxisNo, I32 NewVel, F64 Tacc);

		[DllImport(ExternDLLName, CallingConvention = PCICallingConvention)]
		public static extern ERRCode w1000_get_current_speed(U16 AxisNo);
		#endregion
	}
}
